package org.ljdp.bootstrap;

import org.ljdp.bootstrap.loader.BootClassLoader;
import org.ljdp.bootstrap.loader.ExtLibLoader;
import org.ljdp.bootstrap.loader.WebappLoader;
import org.ljdp.bootstrap.startup.LjdpStartup;
import org.ljdp.bootstrap.startup.ThreadStartup;

/**
 * 类启动加载器
 * @author hzy
 */
public class LauchLoader {
	
	public static void main(String[] args) {
		String currPath = System.getProperty("user.dir");
		try {
			//载入启动器必需类
			BootClassLoader boot = new BootClassLoader(currPath);
			boot.doLoadClass();
			
			//命令行参数解析
			CliParser cliparser = new CliParser();
			AppInfoBean app = cliparser.parser(args);
			
			//载入lib
			ExtLibLoader libLoader = new ExtLibLoader(currPath);
			libLoader.doLoadClass();
			
			//如果是web模式，载入WEB-INF
			if(app.getDeployType().equals(AppInfoBean.DEPLOY_WEB)) {
				WebappLoader webloader = new WebappLoader(currPath, app.getDeployPath());
				webloader.doLoadClass();
			}
			
			if(app.getBootThread() == null) {
				//启动LJDP
				LjdpStartup startup = new LjdpStartup();
				startup.setShutdownThread(app.getShutdownThread());
				startup.run(app.getAppname());
			} else {
				//自定义启动和关闭线程
				ThreadStartup startup = new ThreadStartup(app.getBootThread(), app.getShutdownThread());
				startup.run(app.getAppname());
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}

}
